﻿
/**
*跟单
*/
Chenxin.UI.CustomerTraceForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/traceHandler.ashx',
    id: 'traceWin',
    renderTo: 'jqm_trace',
	defBBtn:true,
    initFormValidator: function() {
        var _this = this;
        $("#houseTraceAddTxtNoticeTime").formValidator({ validatorgroup: this.id,
            onshow: "请输入提醒时间！", onfocus: "请输入提醒时间", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "提醒时间不能为空！" }, onerror: "提醒时间不能为空！"
        });
        $("#houseTraceAddTxtANoticeContent").formValidator({ validatorgroup: this.id,
            onshow: "请输入提醒内容！", onfocus: "请输入提醒内容", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { emptyerror: "提醒内容不能为空！" }, onerror: "提醒内容不能为空！"
        });
        $("#houseTraceAddTxtSummary").formValidator({ validatorgroup: this.id,
            onshow: "跟单内容！", onfocus: "跟单内容", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { emptyerror: "跟单内容不能为空！" }, onerror: "跟单内容不能为空！"
        }).functionValidator({
            fun: function(val, elem) {
                if (val.trim() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "跟单内容不能为空！"
        });
    },
    createForm: function() {
		return Chenxin.FormCommon.customerTraceForm('trace');
        //return formCommon.cstomerTraceForm('trace');
    },
    createComboList: function() {
        var traceType = new Chenxin.UI.Combo({
            containerId: '#followStyle',
            name: 'TraceType',
            tbxWidth: 45,
            required: true,
            items: comboCommon.traceStyle
        });

        return [traceType];
    },
    initEvent: function() {
        var _this = this;
        $('#trace_Save').live('click', function() {
            _this.save();
        });
        $('#trace_Cancle').live('click', function() {
            _this.isNotice = '';
            $('#tr_noticetime').hide();
            $('#tr_noticecontent').hide();
            _this.hide();
        });
        $('#houseTraceAddIsNotice').live('click', function() {
            if (this.checked) {
                $('#tr_noticetime').show();
                $('#tr_noticecontent').show();
            } else {
                $('#houseTraceAddTxtNoticeTime').val("");
                $('#houseTraceAddTxtANoticeContent').val("");
                $('#tr_noticetime').hide();
                $('#tr_noticecontent').hide();
            }
            _this.isNotice = this.checked;
        });
    },
    customerFormVal: function() {
        if ($('houseTraceAddTxtSummary').val()) {
            this.errorMessage = '请填写跟单内容！';
            return false;
        } else {
            return true;
        }
    },
    formValidator: function(model) {
        var status = true;
        if ($('#houseTraceAddIsNotice').attr('checked')) {
            $("#houseTraceAddTxtSummary").unFormValidator(false);
            $("#houseTraceAddTxtNoticeTime").unFormValidator(false);
            $("#houseTraceAddTxtANoticeContent").unFormValidator(false);
            status = jQuery.formValidator.pageIsValid(this.id) && this.checkCombo();
        } else {
            $("#houseTraceAddTxtNoticeTime").unFormValidator(true);
            $("#houseTraceAddTxtANoticeContent").unFormValidator(true);
            $("#houseTraceAddTxtSummary").unFormValidator(false);
            status = jQuery.formValidator.pageIsValid(this.id) && this.checkCombo();
        }
        if (!status) {
            alert(this.errorMessage || '请填写完必填(选)项再进行表单提交！');
        }
        return status;

    },
    initComponent: function() {
        Chenxin.UI.CustomerTraceForm.superclass.initComponent.call(this);
    }
});


/**
*跟单
*/
Chenxin.UI.currentCustomerTraceForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/traceHandler.ashx',
    id: 'traceWin',
    renderTo: 'jqm_trace',
	defBBtn:true,
	show:function(){		
        $('#tr_noticetime').hide();
        $('#tr_noticecontent').hide();
		Chenxin.UI.currentCustomerTraceForm.superclass.show.apply(this,arguments);
	},
    initFormValidator: function() {
        var _this = this;
        $("#houseTraceAddTxtNoticeTime").formValidator({ validatorgroup: this.id,
            onshow: "请输入提醒时间！", onfocus: "请输入提醒时间", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { leftempty: false, rightempty: false, emptyerror: "提醒时间不能为空！" }, onerror: "提醒时间不能为空！"
        });
        $("#houseTraceAddTxtANoticeContent").formValidator({ validatorgroup: this.id,
            onshow: "请输入提醒内容！", onfocus: "请输入提醒内容", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { emptyerror: "提醒内容不能为空！" }, onerror: "提醒内容不能为空！"
        });
        $("#houseTraceAddTxtSummary").formValidator({ validatorgroup: this.id,
            onshow: "跟单内容！", onfocus: "跟单内容", oncorrect: " "
        }).inputValidator({
            min: 1, empty: { emptyerror: "跟单内容不能为空！" }, onerror: "跟单内容不能为空！"
        }).functionValidator({
            fun: function(val, elem) {
                if (val.trim() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "跟单内容不能为空！"
        });
    },
    createForm: function() {
		return Chenxin.FormCommon.customerTraceForm('currenttrace');
        // return formCommon.cstomerTraceForm('currenttrace');
    },
    createComboList: function() {
        var traceType = new Chenxin.UI.Combo({
            containerId: '#followStyle',
            name: 'TraceType',
            tbxWidth: 45,
            required: true,
            items: comboCommon.traceStyle
        });

        return [traceType];
    },
    initEvent: function() {
        var _this = this;
        $('#houseTraceAddIsNotice').live('click', function() {
            if (this.checked) {
                $('#tr_noticetime').show();
                $('#tr_noticecontent').show();
            } else {
                $('#houseTraceAddTxtNoticeTime').val("");
                $('#houseTraceAddTxtANoticeContent').val("");
                $('#tr_noticetime').hide();
                $('#tr_noticecontent').hide();
            }
            _this.isNotice = this.checked;
        });
    },
    customerFormVal: function() {
        if ($('houseTraceAddTxtSummary').val()) {
            this.errorMessage = '请填写跟单内容！';
            return false;
        } else {
            return true;
        }
    },
    formValidator: function(model) {
        var status = true;
        if ($('#houseTraceAddIsNotice').attr('checked')) {
            $("#houseTraceAddTxtSummary").unFormValidator(false);
            $("#houseTraceAddTxtNoticeTime").unFormValidator(false);
            $("#houseTraceAddTxtANoticeContent").unFormValidator(false);
            status = jQuery.formValidator.pageIsValid(this.id) && this.checkCombo();
        } else {
            $("#houseTraceAddTxtNoticeTime").unFormValidator(true);
            $("#houseTraceAddTxtANoticeContent").unFormValidator(true);
            $("#houseTraceAddTxtSummary").unFormValidator(false);
            status = jQuery.formValidator.pageIsValid(this.id) && this.checkCombo();
        }
        if (!status) {
            alert(this.errorMessage || '请填写完必填(选)项再进行表单提交！');
        }
        return status;

    },
    initComponent: function() {
        Chenxin.UI.currentCustomerTraceForm.superclass.initComponent.call(this);
    }
});


/**
*@description 客源跟单
*@comboIdPrefix DIV下拉框和提交按钮前缀
*/
Chenxin.FormCommon.customerTraceForm=function(comboIdPrefix) {

        return '<table class="tbl_f jqTabWh"><tbody> <tr><th style="width:80px; height:25px;">客源编号：</th><td style="width:440px;" ><input type="text" name="CustomerCode" readonly="readonly" class="inputbox_n"/></td></tr><tr><th style="width:80px; height:25px;">所属人员：</th> <td><input type="text" name="AddPerson" class="inputbox_n" readonly="readonly" /></td></tr><tr><th style="width:80px; height:25px;">所属门店：</th> <td><input type="text" name="AddDepart" class="inputbox_n" readonly="readonly" /></td></tr><tr><th>跟单方式：</th><td colspan="3"><div id = "followStyle" style=" margin-right: 5px;"  class="SelectWrapSingle" ></div></td></tr><tr><th> 跟单内容：</th><td colspan="3"><textarea name="TraceContext" id="houseTraceAddTxtSummary" onkeypress="if (this.value.length>=200){event.returnValue=false}"  onchange="if (this.value.length>=200){this.value=this.value.substr(0, 200)}" cols="60" rows="3" class="textarea_n" style="width:420px; height:100px; padding:5px;" /></textarea></td></tr><tr><th>是否提醒：</th> <td><input name="isnotice" type="checkbox" id="houseTraceAddIsNotice" value="1" /></td></tr><tr id="tr_noticetime" style="display:none;height:25px;"><th style="width:70px;">提醒时间：</th><td><input name="SendDate" readonly="readonly" onclick="WdatePicker({position:{left:this.getBoundingClientRect().left+1,top:this.getBoundingClientRect().top+22}});" class="inputbox_n fl" id="houseTraceAddTxtNoticeTime" type="text" style="width:100px;"/></td></tr><tr id="tr_noticecontent" style="display:none;height:25px;"><th style="width:70px;">提醒内容：</th><td colspan="3"><textarea name="body" onkeypress="if (this.value.length>=200){event.returnValue=false}"  onchange="if (this.value.length>=200){this.value=this.value.substr(0, 200)}" id="houseTraceAddTxtANoticeContent" class="textarea_n" style="width:420px; height: 100px; padding:5px;" cols="60" rows="3"></textarea></td></tr> </tbody></table>'
};
//<tr><td></td> <td><div style="float:right; margin-right:25px;_margin-right:3px;*+margin-right:16px;"><a id="' + comboIdPrefix + '_Save" class="btn_n fl" href="#"><span>提交</span></a><a id="' + comboIdPrefix + '_Cancle" class="btn_n fl" href="#"><span>取消</span></a></div></td></tr>